package br.com.honorato.ejb;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.interceptor.Interceptors;

import br.com.honorato.dao.DAdminLoginDAO;
import br.com.honorato.dao.DAdminPassDAO;
import br.com.honorato.exception.DAOException;
import br.com.honorato.exception.EJBServiceException;
import br.com.honorato.logger.Depurador;
import br.com.honorato.logger.InterceptorDeCallback;
import br.com.honorato.logger.LoggerInterceptor;
import br.com.honorato.model.DAdminLogin;
import br.com.honorato.model.DAdminPass;

/**
 * Session Bean implementation class TypeContactEJB
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@Interceptors(
{ Depurador.class, InterceptorDeCallback.class })
public class DomainEJB extends BaseEJB
{
	public static final String JNDI_NAME = "java:module/DomainEJB!br.com.honorato.ejb.DomainEJB";

	public DomainEJB()
	{}

	public DAdminLogin getLoginAdminDefault() throws EJBServiceException
	{
		DAdminLogin out = null;
		List<DAdminLogin> list = new DAdminLoginDAO(getEm()).selectAll();

		for (DAdminLogin dAdminLogin : list)
		{
			out = dAdminLogin;
			break;
		}
		return out;
	}

	public DAdminPass getPassAdminDefault() throws EJBServiceException
	{
		DAdminPass out = null;
		List<DAdminPass> list = new DAdminPassDAO(getEm()).selectAll();

		for (DAdminPass dAdminPass : list)
		{
			out = dAdminPass;
			break;
		}
		return out;
	}

	@LoggerInterceptor
	public void saveDAdminLogin(DAdminLogin domain) throws EJBServiceException
	{
		try
		{
			new DAdminLoginDAO(getEm()).save(domain);
		}
		catch (DAOException e)
		{
			/* TODO: RECUPERAR MENSAGEM DO BUNDLE */
			throw new EJBServiceException(e.getErrorCode(), e.getMessage());
		}
	}

	@LoggerInterceptor
	public void saveDAdminPass(DAdminPass domain) throws EJBServiceException
	{
		try
		{
			new DAdminPassDAO(getEm()).save(domain);
		}
		catch (DAOException e)
		{
			/* TODO: RECUPERAR MENSAGEM DO BUNDLE */
			throw new EJBServiceException(e.getErrorCode(), e.getMessage());
		}
	}
}